import { defineStore } from "pinia";
import type { CategorySelectorlistmodul ,CategoryStateModel} from '@/api/Product/model/CategorySelectormodul'
import {reqgetcategory1list,reqgetcategory2list,reqgetcategory3list} from '@/api/Product/CategorySelector'
let usercategorylist
export default  usercategorylist = defineStore('categorylist',{
    state:():CategoryStateModel => {

        return {
            // 三级选择器选中的数据
            categorySelectorid1 : undefined ,
            categorySelectorid2 : undefined ,
            categorySelectorid3 : undefined ,
            
            // 各级列表数据
             category1list : [] ,
             category2list : [] ,
             category3list : [] ,
        }

    },

    actions:{
        // 请求一级栏数据
        async getcategory1list(){
            let newdata = await reqgetcategory1list()
            this.category1list = newdata
            
        },
        // 请求二级栏数据  设置一级导航时
        async getcategory2list(id:number){
            let newdata = await reqgetcategory2list(id)
            this.categorySelectorid1 = id
            this.categorySelectorid2 = undefined
            this.categorySelectorid3 = undefined
            this.category3list = []
            this.category2list = newdata
        },
        // 请求三级栏数据 设置二级导航时
        async getcategory3list(id:number){
            let newdata = await reqgetcategory3list(id)
            this.categorySelectorid2 = id
            this.category3list = newdata
            this.categorySelectorid3 = undefined
        },
    },

    getters:{

    }

    

})